package org.zero.onlinesubject.utils;

import cn.hutool.crypto.digest.DigestUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Md5Util {

    @Value("${md5.salt}")
    private String salt;

    public String md5(String plainText){
        return DigestUtil.md5Hex(plainText);
    }

    public String inputPassToFormPass(String inputPass){
        String pass = salt.charAt(5) + salt.charAt(2) + inputPass + salt.charAt(0)+ salt.charAt(1);
        return md5(pass);
    }

    public String formPassToDBPass(String formPass){
        String pass = salt.charAt(5) + salt.charAt(2) + formPass + salt.charAt(0)+ salt.charAt(1);
        return md5(pass);
    }

    public String inputPassToDBPass(String inputPass){
        return formPassToDBPass(inputPassToFormPass(inputPass));
    }
}
